%% Produce Figure 5

addpath('functions');
addpath('data')

% Coloured Figures

red = [1 0 0];
blue = [0 0 1];
green = [0 0.7 0.3];
yellow = [1 0.8 0];
cyan = [0 .69 0.94];


% Black and White Figures

red = [0 0 0];
blue = [0.2 0.2 0.2];
green = [0.5 0.5 0.5];
yellow = [0.7 0.7 0.7];
cyan = [0.2 0.2 0.2];

%% Figure 5a - Posterior Estimates of Labor Productivity Trends
annualise = 1;


load('output\results_Figure5_JP')
v2struct(settings);
v2struct(results);
trends = nanmean(squeeze(Draws_Factors(:,1:trend,:)),3);

hourstrend_JP = means(3)+3*trends(:,2);
TFP_trend_JP = means(1)-means(3)+3*trends(:,1);
datesjp = dates;

load('output\results_Figure5_CA')
v2struct(settings);
v2struct(results);
trends = nanmean(squeeze(Draws_Factors(:,1:trend,:)),3);
hourstrend_CA = means(3)+3*trends(:,2);
TFP_trend_CA = means(1)-means(3)+3*trends(:,1);
datesca = dates;


load('output\results_Figure5_UK')
v2struct(settings);
v2struct(results);
trends = nanmean(squeeze(Draws_Factors(:,1:trend,:)),3);
hourstrend_UK = means(3)+3*trends(:,2);
TFP_trend_UK = means(1)-means(3)+3*trends(:,1);
datesuk = dates;

load('output\results_Figure4')
v2struct(settings);
v2struct(results);
trends = nanmean(squeeze(Draws_Factors(:,1:trend,:)),3);
hourstrend_US = means(3)+3*trends(:,2);
TFP_trend_US = means(1)-means(3)+3*trends(:,1);
datesus=dates;


load('output\results_Figure5_IT')
v2struct(settings);
v2struct(results);
trends = nanmean(squeeze(Draws_Factors(:,1:trend,:)),3);
hourstrend_IT = means(3)+3*trends(:,2);
TFP_trend_IT = means(1)-means(3)+3*trends(:,1);

load('output\results_Figure5_DE')
v2struct(settings);
v2struct(results);
trends = nanmean(squeeze(Draws_Factors(:,1:trend,:)),3);
hourstrend_DE = means(3)+3*trends(:,2);
TFP_trend_DE = means(1)-means(3)+3*trends(:,1);

load('output\results_Figure5_FR')
v2struct(settings);
v2struct(results);
trends = nanmean(squeeze(Draws_Factors(:,1:trend,:)),3);
hourstrend_FR = means(3)+3*trends(:,2);
TFP_trend_FR = means(1)-means(3)+3*trends(:,1);

% Compute average for EA
hourstrend_EA = (hourstrend_IT+hourstrend_DE+hourstrend_FR)./3;
TFP_trend_EA = (TFP_trend_IT+TFP_trend_DE+TFP_trend_FR)./3;


%%

f = figure(1);
plot(datesus(q+1:end,1),TFP_trend_US,'color',red,'LineWidth',3)
hold on
plot(dates(q+1:end,1),TFP_trend_JP,'LineStyle',':','color',green,'LineWidth',3)
plot(dates(q+1:end,1),TFP_trend_CA,'LineStyle','-.','color',blue,'LineWidth',3)
plot(datesuk(q+1:end,1),TFP_trend_UK,'color',yellow,'LineWidth',3)
if max(red) == 0
plot(dates(q+1:end,1),TFP_trend_EA,'LineStyle','--','color',cyan,'LineWidth',3)    
else
plot(dates(q+1:end,1),TFP_trend_EA,'color',cyan,'LineWidth',3)
end
hold off

legend('US','JP','CA','UK','Euro Area','Location','NorthOutside','Orientation','horizontal')
legend('boxoff')

datesToPlot = datenum(1960:10:2020,1,1);
YAxisTicks = [0:2:8];
set(gca,'XTick',datesToPlot,'GridLineStyle',':','YTick',YAxisTicks)
datetick('x','yyyy','keepticks')
xlim([datenum(1960,1,1),datenum(2016,1,1)])

ymin = 0;
ymax = 7;
ylim([ymin,ymax])
grid on
box on

figSize = [10 7];
set(f, 'PaperUnits', 'inches');
set(f, 'Units','inches');
set(f, 'PaperSize', figSize);
set(f, 'PaperPositionMode', 'auto');
set(f, 'Position', [0 0 figSize(1) figSize(2)])
set(gca, 'FontName', 'Times-Roman');
set(gca, 'FontSize', 20);
set(gca,'Layer','Top')

ti = get(gca,'TightInset');
set(gca,'Position',[1.1*ti(1) 1.1*ti(2) 0.99*(1-ti(3)-ti(1)) 0.95*(1-ti(4)-ti(2))]);


fname = strcat('output\Figure5a.pdf');
print('-dpdf', f, fname);


%%

f = figure(2);
plot(datesus(q+1:end,1),hourstrend_US,'color',red,'LineWidth',3)
hold on
plot(dates(q+1:end,1),hourstrend_JP,'LineStyle',':','color',green,'LineWidth',3)
plot(dates(q+1:end,1),hourstrend_CA,'LineStyle','-.','color',blue,'LineWidth',3)
plot(datesuk(q+1:end,1),hourstrend_UK,'color',yellow,'LineWidth',3)
if max(red) == 0
plot(dates(q+1:end,1),hourstrend_EA,'LineStyle','--','color',cyan,'LineWidth',3)    
else
plot(dates(q+1:end,1),hourstrend_EA,'color',cyan,'LineWidth',3)
end
hold off

legend('US','JP','CA','UK','Euro Area','Location','NorthOutside','Orientation','horizontal')
legend('boxoff')

datesToPlot = datenum(1960:10:2020,1,1);
YAxisTicks = [-2:2:8];
set(gca,'XTick',datesToPlot,'GridLineStyle',':','YTick',YAxisTicks)
datetick('x','yyyy','keepticks')
xlim([datenum(1960,1,1),datenum(2016,1,1)])

ymin = -2;
ymax = 3;
ylim([ymin,ymax])
grid on
box on

figSize = [10 7];
set(f, 'PaperUnits', 'inches');
set(f, 'Units','inches');
set(f, 'PaperSize', figSize);
set(f, 'PaperPositionMode', 'auto');
set(f, 'Position', [0 0 figSize(1) figSize(2)])
set(gca, 'FontName', 'Times-Roman');
set(gca, 'FontSize', 20);
set(gca,'Layer','Top')

ti = get(gca,'TightInset');
set(gca,'Position',[1.1*ti(1) 1.1*ti(2) 0.99*(1-ti(3)-ti(1)) 0.95*(1-ti(4)-ti(2))]);


fname = strcat('output\Figure5b.pdf');
print('-dpdf', f, fname);

%%




